package cn.gjxblog.consumer;

import cn.gjxblog.Barista;
import com.rabbitmq.client.Channel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.support.AmqpHeaders;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.annotation.StreamListener;
import org.springframework.messaging.Message;
import org.springframework.stereotype.Service;

import java.io.IOException;


/**
 * @author gjx
 * @version v1.0
 * @Description
 * @date 2019/7/5 17:24
 */
@EnableBinding(Barista.class)
@Service
@Slf4j
public class RabbitReceiver {
    @StreamListener(Barista.INPUT_CHANNEL)
    public void receiver(Message message) throws IOException {
        Channel channel = (Channel) message.getHeaders().get(AmqpHeaders.CHANNEL);
        Long id = (Long) message.getHeaders().get(AmqpHeaders.DELIVERY_TAG);

        log.info("receiver receive message is" + message);
        channel.basicAck(id,false);
    }
}
